package com.pfzy.utildemo.activity.record;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;

import com.pfzy.lib.config.log.MyLog;
import com.pfzy.utildemo.R;
import com.pfzy.utildemo.activity.base.BaseActivity;
import com.pfzy.utildemo.activity.record.soundrecord.RecordingInfo;
import com.pfzy.utildemo.activity.record.soundrecord.RecordingService;
import com.pfzy.utildemo.databinding.ActivityRecordBinding;

public class RecordActivity extends BaseActivity implements View.OnClickListener {
    private ActivityRecordBinding mBind;

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        mBind = ActivityRecordBinding.inflate(getLayoutInflater());
        setContentView(mBind.getRoot());

        initView();
    }

    private void initView() {
        mBind.start.setOnClickListener(this);
        mBind.end.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.start:
                break;
            case R.id.end:
                break;
            default:
                break;
        }
    }

    /**
     * 实际开始录制
     */
    private void StartRecording(RecordingInfo recordingInfo) {
        _logd("actualStartRecording recordingInfo : " + (recordingInfo == null ? "" : recordingInfo.toString()));
        Intent intent = new Intent(this, RecordingService.class);
        intent.setAction(RecordingService.ACTION_START_RECORD);
        intent.putExtra(RecordingService.KEY_TRANSMIT_DATA_TO_SERVICE, recordingInfo);
        this.startService(intent);
    }

    /**
     * 停止录音
     */
    public void stopRecording(RecordingInfo recordingInfo) {
        _logd("stopRecording recordingInfo : " + (recordingInfo == null ? "" : recordingInfo.toString()));
        Intent intent = new Intent(this, RecordingService.class);
        intent.setAction(RecordingService.ACTION_STOP_RECORD);
        intent.putExtra(RecordingService.KEY_TRANSMIT_DATA_TO_SERVICE, recordingInfo);
        this.startService(intent);
    }

    private void _logd(String msg) {
        MyLog.logd("录音活动 " + msg);
    }
}
